package simulation;

import streaming.StreamingConfig;
import streaming.Tracker;

public class TrackerPeriodicUpdate implements EventHandler {
	Tracker tracker;
	Simulator sim;
	
	public TrackerPeriodicUpdate(Tracker tracker) {
		this.setTracker(tracker);
		this.setSim(Simulator.getInstance());
	}
	
	public void addEvent() {
		double time = this.getSim().getTime() + this.getInterval();
		if (Math.abs(time - Math.round(time)) < 0.00001)
			time = Math.round(time);
		this.getSim().addEvent(time, this);
	}
	
	public void run(double time) {
		this.getTracker().updateStatus();
	}

	/* Getters and Setters */

	public Tracker getTracker() {
		return tracker;
	}

	public void setTracker(Tracker tracker) {
		this.tracker = tracker;
	}

	public Simulator getSim() {
		return sim;
	}

	public void setSim(Simulator sim) {
		this.sim = sim;
	}

	/**
	 * Get interval of updates execution for tracker
	 * @return The interval time to execute the update method.
	 */
	public double getInterval() {
		return StreamingConfig.TRACKER_UPDATE_INTERVAL;
	}
}
